<%-- 
    Document   : showAdmin
    Created on : Aug 20, 2012, 1:46:16 PM
    Author     : HungDQ
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<div class="section table_section">
    <!--[if !IE]>start title wrapper<![endif]-->
    <div class="title_wrapper">
        <h2>Management Projects</h2>
        <span class="title_wrapper_left"></span>
        <span class="title_wrapper_right"></span>
    </div>
    <!--[if !IE]>end title wrapper<![endif]-->

    <!--[if !IE]>start section content<![endif]-->
    <div class="section_content">
        <!--[if !IE]>start section content top<![endif]-->
        <div class="sct">
            <div class="sct_left">
                <div class="sct_right">
                    <div class="sct_left">
                        <div class="sct_right">
                            <!--[if !IE]>start table_wrapper<![endif]-->
                            <div class="table_wrapper">
                                <div class="table_wrapper_inner">
                                <div id="container">
                                    <!------------------------------------------------->
                                    <!------------------------------------------------->
                                    <!------------------------------------------------->

                                    <%
                                    Object message = request.getSession().getAttribute("MESS");
                                    if(message != null && !message.equals(""))
                                    {
                                        out.println("<script>alert(\""+message.toString()+"\");</script>");
                                        request.getSession().removeAttribute("MESS");
                                    }

                                    String Filter = request.getParameter("Filter");
                                    String month = request.getParameter("month");
                                    String year = request.getParameter("year");
                                    String with = request.getParameter("with");
                                    String price = request.getParameter("price");
                                    String status = request.getParameter("status");
                                    %>

                                    <div style="padding-bottom: 15px; padding-top: 5px; width: 100%; text-align: center" >
                                        <form action="?option=project" method="post">
                                            <ul class="right">
                                                <li>
                                                    Filter Infomation          
                                                    Received At : Month :
                                                    <select name="month">
                                                        <option value="0">-</option>
                                                        <%
                                                        for(int i=1; i<=12;i++)
                                                        {
                                                           %><option value="<%=i %>" <% if(request.getParameter("month") != null) { if(Integer.parseInt(request.getParameter("month"))==i) out.print("selected"); } %> ><%=i %></option><%
                                                        }
                                                        %>
                                                    </select>
                                                    Year :
                                                    <select name="year">
                                                        <option value="0">-</option>
                                                        <%
                                                        int yearNow = org.nvdung.util.UtilDateTime.getCurrentYear();
                                                        for(int i=yearNow-5; i<=yearNow;i++)
                                                        {
                                                            %><option value="<%=i %>" <% if(request.getParameter("year") != null) { if(Integer.parseInt(request.getParameter("year"))==i) out.print("selected"); } %> ><%=i %></option><%
                                                        }
                                                        %>
                                                    </select>          
                                                    Total Price :
                                                    <select name="with">
                                                        <%
                                                        String strWith = "";
                                                        if(with != null)
                                                            strWith = with.toString();
                                                        %>
                                                        <option value="=" <% if(strWith.equals("=")) out.print("selected"); %> >=</option>
                                                        <option value="<" <% if(strWith.equals("<")) out.print("selected"); %> ><</option>
                                                        <option value=">" <% if(strWith.equals(">")) out.print("selected"); %> >></option>
                                                    </select>

                                                        <input type="text" style="width: 75px;" value="<% if(price != null && !price.equals("0")) out.print(price.toString()); %>" name="price" />          
                                                    Status :
                                                    <select name="status">
                                                        <%
                                                        String strStatus = "";
                                                        if(status != null)
                                                            strStatus = status.toString();
                                                        %>
                                                        <option value="-1" selected >-</option>
                                                        <option value="0" <% if(strStatus.equals("0")) out.print("selected"); %> >Pending</option>
                                                        <option value="1" <% if(strStatus.equals("1")) out.print("selected"); %> >Denied</option>
                                                        <option value="2" <% if(strStatus.equals("2")) out.print("selected"); %> >Accepted</option>
                                                        <option value="3" <% if(strStatus.equals("3")) out.print("selected"); %> >Paided</option>
                                                        <option value="4" <% if(strStatus.equals("4")) out.print("selected"); %> >On-Going</option>
                                                        <option value="5" <% if(strStatus.equals("5")) out.print("selected"); %> >Accomplished</option>
                                                    </select>          
                                                    <input name="Filter" type="submit" value="Filter" />
                                                </li>
                                            </ul>
                                        </form>
                                    </div>


                                    <%
                                    Object objAppCon = application.getAttribute("APP_CONN");
                                    java.util.ArrayList<org.nvdung.bean.Project> al = new java.util.ArrayList<org.nvdung.bean.Project>();
                                    if(objAppCon != null)
                                    {
                                        java.sql.Connection connection = (java.sql.Connection)objAppCon;
                                        org.nvdung.db.SqlProjects sql = new org.nvdung.db.SqlProjects(connection);
                                        
                                        if(Filter != null)
                                        {
                                            int _month = 0;
                                            int _year = 0;
                                            double _price = 0;
                                            int _status = -1;
                                            if(price == null || price.equals(""))
                                            {
                                                price = "0";
                                            }
                                            if (org.nvdung.util.UtilValidateInput.isDouble(price)){
                                                _month = Integer.parseInt(month);
                                                _year = Integer.parseInt(year);
                                                _price = Double.parseDouble(price);
                                                _status = Integer.parseInt(status);
                                                
                                                al = sql.getSearchProject(_month, _year, with, _price, _status);
                                            } else {
                                                 %><script>alert("Price Invalid !"); window.history.go(-1);</script><%
                                            }
                                        } else {
                                            al = sql.getAllProject();
                                        }
                                        
                                        if(al.size() > 0)
                                        {
                                    %>

                                    
                                    <form action="#">
                                    <fieldset>
                                    <div id="demo">
                                        <table cellpadding="0" width="100%" cellspacing="0" border="0" class="display" id="nvdung">
                                            <thead>
                                                <tr>
                                                    <th width="5%" align="center">ID</th>
                                                    <th width="13%" align="center">Received At</th>
                                                    <th width="32%" align="center">Project Name</th>
                                                    <th width="15%" align="center">Total Price</th>
                                                    <th width="15%" align="center">Customer Name</th>
                                                    <th width="12%" align="center">Status</th>
                                                    <th width="5%" align="center">Action</th>
                                                </tr>
                                            </thead>
                                            <%
                                            for(int i=0;i<al.size();i++)
                                            {
                                                org.nvdung.bean.Project cus = al.get(i);
                                            %>
                                                <tr>
                                                    <td><%=cus.getProjectID() %></td>
                                                    <td style="text-align: center;"><%=org.nvdung.util.UtilDateTime.getTimeString(cus.getReceived(), "dd/MM/yyyy hh:mm a") %></td>
                                                    <td><a class="product_name" href="?option=project&action=edit&id=<%=cus.getProjectID() %>"><%=cus.getProjectName() %></a></td>
                                                    <td><%=cus.getTotalPrice() %></td>
                                                    <td><a href="?option=member&action=edit&id=<%=cus.getMemberID() %>"><%=cus.getCustomerName() %></a></td>
                                                    <td style="text-align: center;">
                                                        <%
                                                        int isStatus = cus.getStatus();
                                                        if(isStatus == 1) {
                                                            %> <span class="nvdung_block">Denied</span><%
                                                        } else if(isStatus == 0) {
                                                            %> <span class="nvdung_pending">Pending</span><%
                                                        } else if(isStatus == 2) {
                                                            %> <span class="nvdung_accpect">Accepted</span><%
                                                        } else if(isStatus == 3) {
                                                            %> <span class="nvdung_money">Paided</span><%
                                                        } else if(isStatus == 4) {
                                                            %> <span class="nvdung_on_going">On-Going</span><%
                                                        } else if(isStatus == 5) {
                                                            %> <span class="nvdung_active">Accomplished</span><%
                                                        }
                                                        %>
                                                    </td>
                                                    <td align="center">
                                                        <div class="actions_menu">
                                                            <ul>
                                                                <li><a class="edit" href="?option=project&action=edit&id=<%=cus.getProjectID() %>">Edit</a></li>
                                                                <!--<li><a class="delete" onclick="return confirm('Do you want delete project with id = <=cus.getProjectID() %> ?');" href="javascript: gotoDelete('<=cus.getProjectID()%>');">Delete</a></li>-->
                                                            </ul>
                                                        </div>
                                                    </td>
                                                </tr>
                                            <%
                                            }
                                            %>
                                        </table>
                                    </div>
                                    </fieldset>
                                    </form>
                                    <%
                                        }
                                    }
                                    %>
                                    
                                </div>
                                </div>
                            </div>
                            <!--[if !IE]>end table_wrapper<![endif]-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--[if !IE]>end section content top<![endif]-->
        <!--[if !IE]>start section content bottom<![endif]-->
        <span class="scb"><span class="scb_left"></span><span class="scb_right"></span></span>
        <!--[if !IE]>end section content bottom<![endif]-->
    </div>
    <!--[if !IE]>end section content<![endif]-->
</div>

<form name="frmDelete" method="get" action="../nvdung/project/delete">
    <input type="hidden" name="id" value="" />
</form>
<script>
    function gotoDelete(deleteValue) {
        document.frmDelete.id.value = deleteValue;
        document.frmDelete.submit();
    }
</script>